package com.yiwei.zxp.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class SureRefereeDilaog extends Dialog {


    @BindView(R.id.btn_cancel)
    ImageView btnCancel;
    @BindView(R.id.txt_invite_code)
    TextView txtInviteCode;
    @BindView(R.id.btn_change)
    TextView btnChange;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    private Context context;


    public SureRefereeDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public SureRefereeDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_sure_referee);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.CENTER;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = Util.getDisplayMetrics(context).heightPixels / 10 * 8;
        } else {
            lp.width = Util.getDisplayMetrics(context).widthPixels / 10 * 8;
        }
        mWindow.setAttributes(lp);

    }


    public void setInviteData(String code) {
        txtInviteCode.setText(code);
    }


    private OnChooseListener onChooseListener;

    public SureRefereeDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    @OnClick({R.id.btn_cancel, R.id.btn_change, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_change:
                dismiss();
                break;
            case R.id.btn_submit:
                if (onChooseListener != null) {
                    onChooseListener.onSure();
                }
                dismiss();
                break;
        }
    }


    public interface OnChooseListener {
        void onSure();
    }
}
